package com.hjx.servlet;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.hjx.service.userService;

public class registerServlet extends HttpServlet {
    private String[] args=null;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //count得放到这，不然count的值为前一个的，可能一直>0
        int count=0;
        userService user=new userService();
        String username=req.getParameter("user");
        String pass=req.getParameter("pass");
        args= new String[]{
                username, pass,"","",""
        };
        try {
            if(username!=null && username!="" && pass!=null && pass!=""){
                count=user.addUser(args);
            }else{
                System.out.println("用户输入数据为空");
//                这里不能进行重定向，把重定向放到catch代码块即可
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
            if (count>=1){
                System.out.println("注册成功");
                resp.sendRedirect("/super/LoginValidate/login.jsp");
            }else{
                System.out.println("注册失败！！");
                resp.sendRedirect("/super/LoginValidate/registerFail.jsp");
            }



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}

